package tgc.edu.xzy.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import tgc.edu.xzy.entity.TbFile;
import tgc.edu.xzy.service.FileService;

@Controller
public class FileController {
	@Autowired
	private FileService service;
	
	@RequestMapping(value="/list")
	public String list(ModelMap map) {
		List<TbFile> list = service.findAll();
		map.put("models", list);
		return "list";
	}
	
	@RequestMapping(value="/edit")
	public String edit() {
		return "edit";
	}
	
	@RequestMapping(value="/save")
	public String save(MultipartFile file) {
		service.save(file);
		return "redirect:list";
	}
	
	@RequestMapping(value="/download")
	@ResponseBody
	public Object download(Integer id, HttpServletRequest request, HttpServletResponse response) {
		service.download(id, request, response);
		return null;
	}
}
